package ventana;

import javax.swing.DefaultListModel;
import spring.main.Lector;
import spring.main.Posteador;

public class VentanaPrincipal extends javax.swing.JFrame {

    private Posteador posteador;
    private Lector lector = new Lector();
    DefaultListModel modelTweets = new DefaultListModel();
    DefaultListModel modelAmigos = new DefaultListModel();
//    String codigo;
//    OAuthService service;
//    Token requestToken;

    public VentanaPrincipal(String nombreUsuario) {
        initComponents();
        listaTweets.setModel(modelTweets);
        listaAmigos.setModel(modelAmigos);
        this.setTitle("Twitter de "+"@"+nombreUsuario);
        //labelTwitter.setText(labelTwitter.getText()+"@"+nombreUsuario);
        this.lector.actualizar(this.modelTweets, this.modelAmigos);
//        this.codigo=codigo;
//        this.service=service;
//        this.requestToken=requestToken;

        // this.posteador=posteador;
    }

    public void setLector(Lector lector) {
        this.lector = lector;
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        scorlListaTweets = new javax.swing.JScrollPane();
        listaTweets = new javax.swing.JList();
        botonVer = new javax.swing.JButton();
        scorlListaTweets1 = new javax.swing.JScrollPane();
        listaAmigos = new javax.swing.JList();
        botonTweetear = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setBackground(new java.awt.Color(0, 204, 255));

        scorlListaTweets.setViewportView(listaTweets);

        botonVer.setText("Ver Tweets");
        botonVer.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonVerActionPerformed(evt);
            }
        });

        scorlListaTweets1.setViewportView(listaAmigos);

        botonTweetear.setText("Tweetear");
        botonTweetear.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonTweetearActionPerformed(evt);
            }
        });

        jLabel1.setText("Tweets");

        jLabel2.setText("Estas siguiendo a:");

        jMenu1.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jMenu1.setText("HOME");
        jMenu1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenu1ActionPerformed(evt);
            }
        });
        jMenuBar1.add(jMenu1);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel1)
                        .addGap(0, 550, Short.MAX_VALUE))
                    .addComponent(scorlListaTweets))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(botonVer)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(botonTweetear))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jLabel2)
                        .addComponent(scorlListaTweets1, javax.swing.GroupLayout.PREFERRED_SIZE, 208, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(scorlListaTweets1, javax.swing.GroupLayout.DEFAULT_SIZE, 383, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(botonTweetear)
                            .addComponent(botonVer))
                        .addGap(24, 24, 24))
                    .addComponent(scorlListaTweets)))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void botonVerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonVerActionPerformed
         lector.verTweetsAmigo(this.modelTweets, this.modelAmigos,(String)listaAmigos.getSelectedValue());
    }//GEN-LAST:event_botonVerActionPerformed

    private void botonTweetearActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonTweetearActionPerformed
        lector.tweetearAmigo((String)listaAmigos.getSelectedValue());
    }//GEN-LAST:event_botonTweetearActionPerformed

    private void jMenu1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenu1ActionPerformed
        this.jLabel1.setText("CAMBIOOOO");
        this.lector.actualizar(this.modelTweets, this.modelAmigos);
    }//GEN-LAST:event_jMenu1ActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton botonTweetear;
    private javax.swing.JButton botonVer;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JList listaAmigos;
    private javax.swing.JList listaTweets;
    private javax.swing.JScrollPane scorlListaTweets;
    private javax.swing.JScrollPane scorlListaTweets1;
    // End of variables declaration//GEN-END:variables

    /**
     * @param posteador the posteador to set
     */
    public void setPosteador(Posteador posteador) {
        this.posteador = posteador;
    }
}
